<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>15-4 给对象添加iterator属性让他完全支持for...of循环（属性可以是字符串）</title>
</head>

<body>
  <script>
    let obj = {
      name: "henry",
      age: 22,
      [Symbol.iterator]() {
        let self = this, index = 0,
          key = [
            ...Object.keys(self),
            ...Object.getOwnPropertySymbols(self)
          ].filter(item => item !== Symbol.iterator);
        return {
          next() {
            return index >= key.length
              ? {
                done: true,
                value: 'undefined'
              } : {
                done: false,
                value: self[key[index++]]
              }
          }
        }
      }
    }
    for (let val of obj) {
      console.log(val)
    }
  </script>
</body>

</html>